#pragma once
#include "ChatUtils.h"

class ChatLogicModule;

class ChatMainWindow : public WindowImplBase
{
public:
	ChatMainWindow();
	virtual ~ChatMainWindow();

public:
	void InitWindow();
	void InitResource();

	virtual CDuiString GetSkinFile();
	virtual LPCTSTR GetWindowClassName()const;

	void OnFinalMessage(HWND hWnd);
	LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

	void SetChatLogicModule(ChatLogicModule* pModule);

public Dui_Slots:
	void OnSubmitChat(CControlUI* pCtrl);
	void OnSystemBtnClicked(CControlUI* pCtrl);
	void OnSelectSession(CControlUI* pCtrl, int index);
	void OnSelectFriend(CControlUI* pCtrl, int index);

	void OnRecvChatMsg(SessionId sessionId, ChatMsgId chatMsgId);
	void OnRecvFriendList();
	void OnNewSession(SessionId sessionId);

	void OnFriendSettingChanged(const CModelIndex& index, const CVar& oldValue, const CVar& newValue);

private:
	void CreateAllModels();

	void ShowCurrentSessionChatList();

	void InsertDataToChatListModel(const ChatMsg& chatMsg);
	void InsertToSessionModel(SessionId sessionId, ChatMsgId chatMsgId);
	void InsertToChatListModel(SessionId sessionId, ChatMsgId chatMsgId);
	void InsertToChatCountModel(SessionId sessionId, ChatMsgId chatMsgId);

private:
	ChatLogicModule* m_pChatModule;

	CAbstractItemModel* m_pChatListModel;
	CAbstractItemModel* m_pSessionModel;
	CAbstractItemModel* m_pFriendModel;
	CAbstractItemModel* m_pChatCountModel;

	SessionId m_CurrentSession;
};

